const defaultState = {
    //默认值
    breadList: [],
    kanjiaList: [],  // 砍价列表
    kanjiaShop: [],  // 砍价商品 
    commanderAdminList: [],
    //团长审核数据
    commanderCheckList2: [],
    //团长管理数据 用来筛选
    commanderAdminListFilter: [],
    //团长审核数据 用来筛选
    commanderCheckList2Filter: [],
    //团长管理数据 里面的 绑定商品数据
    commanderAdminListGoods: [],
    //商品数据
    goodsLists: [],
}

const reducer = (state = defaultState, action) => {
    let { type, payload } = action;
    switch (type) {
        case "Breadcrumb": {
            // console.log(payload)

            return {
                ...state,
            }
        }
        // 砍价列表
        case "DATA_KANJIA": {
            // console.log(payload)
            return {
                ...state,
                kanjiaList: payload
            }
        }
        // 砍价商品
        case "DATA_KANJIA_SHOP": {
            return {
                ...state,
                kanjiaShop: payload
            }
        }
        case "COMMANDER_LIST": { //团长管理数据
            return {
                ...state,
                commanderAdminList: payload,
                commanderAdminListFilter: payload
            }
        }
        case "COMMAND_CHECK_LIST2": { //团长审核数据
            return {
                ...state,
                commanderCheckList2: payload,
                commanderCheckList2Filter: payload
            }
        }
        case "SEARCH_COMMANDERAMDIN_LIST": { //团长管理搜索
            console.log(payload)
            return {
                ...state,
                commanderAdminList: payload
            }
        }
        case "SELECTVALUE_COMMANDERADMIN": { //团长管理下拉搜索
            let result = []
            if (payload.value === "全部") {
                result = state.commanderAdminListFilter
            } else {
                result = state.commanderAdminListFilter.filter(item => item.lls.indexOf(payload.value) !== -1)
            }
            return {
                ...state,
                commanderAdminList: result
            }
        }
        //团长审核搜索
        case "SEARCH_COMMANDERCHECK2_LIST": {
            console.log(payload)
            return {
                ...state,
                commanderCheckList2: payload
            }
        }
        case "SELECTVALUE_COMMANDERCHECK": { //团长审核下拉搜索
            let result2 = []
            if (payload.value === "全部") {
                result2 = state.commanderCheckList2Filter
            } else {
                result2 = state.commanderCheckList2Filter.filter(item => item.lls.indexOf(payload.value) !== -1)
            }
            return {
                ...state,
                commanderCheckList2: result2
            }
        }
        case "PASS_COMMANDER_CHECK_LIST": { //团长审核的审核通过
            const result3 = state.commanderCheckList2.map(item => {
                if (item.id === payload.id) {
                    return {
                        ...item,
                        lls: "成功",
                        color: "blue"
                    }
                }
                return item
            })
            return {
                ...state,
                commanderCheckList2: result3
            }
        }
        case "UNPASS_COMMANDER_CHECK_LIST": { //团长审核中审核不通过
            const result4 = state.commanderCheckList2.map(item => {
                if (item.id === payload.id) {
                    return {
                        ...item,
                        lls: "失败",
                        color: "red"
                    }
                }
                return item
            })
            return {
                ...state,
                commanderCheckList2: result4
            }
        }
        //团长管理的绑定商品
        case "ADD_COMMANDERADMIN_LIST": {
            //将该商品添加到商品行列
            state.goodsLists.push(payload)
            return {
                ...state
            }
        }
        //团长管理的编辑
        case "EDIT_COMMANDERADMIN_LIST": {
            const result5 = state.commanderAdminList.map(item => {
                if (item.id === payload.id) {
                    return {
                        ...item,
                        name: payload.name,
                        tel: payload.tel,
                        city: payload.city,
                        ziti: payload.ziti,
                        sname: payload.sname,
                        lls: payload.lls,
                        shentime: payload.shentime
                    }
                }
                return item
            })
            return {
                ...state,
                commanderAdminList: result5
            }
        }
        default: {
            return {
                ...state
            }
        }
    }
}

export default reducer